<template>
  <div>
    <el-form :model="npcTaskData" style="margin:10px">
      <el-row>
        <el-col :span="4">
          <div class="col_label">采购组织</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.purOrgName}}</div>
        </el-col>
        <el-col :span="4">
          <div class="col_label">采购组</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.purGroupName}}</div>
        </el-col>
        <el-col :span="4">
          <div class="col_label">工厂</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.factoryName}}</div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="4">
          <div class="col_label">任务编码</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.taskCode}}</div>
        </el-col>
        <el-col :span="4">
          <div class="col_label">任务名称</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.taskName}}</div>
        </el-col>
        <el-col :span="4">
          <div class="col_label">打样类型</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.npcTypeStr}}</div>
        </el-col>
      </el-row>
      <el-row>
         <el-col :span="4">
          <div class="col_label">品类</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.categoryName}}</div>
        </el-col>
        <el-col :span="4">
          <div class="col_label">样品接收岗位</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.sysStationName}}</div>
        </el-col>
        <el-col :span="4">
          <div class="col_label">发布人</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.publishUserName}}</div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="4">
          <div class="col_label">发布状态</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.publishStatusStr}}</div>
        </el-col>
        <el-col :span="4">
          <div class="col_label">发布日期</div>
        </el-col>
        <el-col :span="4">
          <div class="col_view">{{npcTaskData.publishTime}}</div>
        </el-col>
        <el-col :span="4">
          <div class="col_label">审核状态</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.checkStatusStr}}</div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="4">
          <div class="col_label">审核人</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.checkUserName}}</div>
        </el-col>
        <el-col :span="4">
          <div class="col_label">审核日期</div>
        </el-col>
        <el-col :span="4">
          <div class="col_view">{{npcTaskData.checkTime}}</div>
        </el-col>
        <el-col :span="4">
          <div class="col_label">审核意见</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.checkOpinion}}</div>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="4">
          <div class="col_label">确认状态</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.confirmStatusStr}}</div>
        </el-col>
        <el-col :span="4">
          <div class="col_label">是否含驳回项</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.existRefuseStr}}</div>
        </el-col>
        <el-col :span="4">
          <div class="col_label">完成状态</div>
        </el-col>
        <el-col :span="4">
          <div class="col_view">{{npcTaskData.completeStatusStr}}</div>
        </el-col>
      </el-row>
      <el-row>
         <el-col :span="4">
          <div class="col_label">是否短信/邮件通知</div>
        </el-col>
        <el-col :span="4">
          <div  class="col_view">{{npcTaskData.shortMessage == 0 ? '否' : '是'}}</div>
        </el-col>
        <el-col :span="4" class="col_label">附件</el-col>
        <el-col :span="12" class="col_view">
          <a href="javascript:;" @click="downloadFiles(npcTaskData.attachmentUrl,npcTaskData.attachmentName)" class="download_color">{{npcTaskData.attachmentName}}</a>        
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="4">
          <div class="col_label">通告</div>
        </el-col>
        <el-col :span="20">
          <div class="col_view">{{npcTaskData.notice}}</div>
        </el-col>
      </el-row>
    </el-form>
    <el-dialog title="审核" :visible.sync="dialogFormVisible">
      <el-form :model="checkForm">
        <el-form-item label="结论" :label-width="formLabelWidth">
            <template>
              <el-radio-group v-model="checkForm.dg_checkStatus">
                <el-radio-button v-for="checkOption in checkOptions" :label="checkOption[0]" :key="checkOption[0]">{{checkOption[1]}}</el-radio-button>
              </el-radio-group>
            </template>
          </el-form-item>
        <el-form-item label="审核意见" :label-width="formLabelWidth">
          <el-input type="textarea" v-model="checkForm.dg_checkContent" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitCheck(checkForm)">提交</el-button>
        <el-button @click="dialogFormVisible = false">取消</el-button>
      </div>
    </el-dialog>
    <div style="margin:10px">
      <el-button v-if="checkStatus == 3"  class = "fr" type="danger" @click="check()" style="margin-left: 16px;">审核</el-button>
      <el-button v-if="publishStatus == 0" class = "fr" type="danger" @click="publish()" style="margin-left: 16px;">发布</el-button>
    </div>
  </div>
</template>
<script>
  import qs from 'qs';
  export default {
    data() {
      return {
        // 初始化页面按钮控制
        publishStatus:0,
        checkStatus:0,
        // 新增、修改专家的标签默认值
        checkOptions: [['1','通过'], ['-1','驳回']],
        formLabelWidth:'120px',
        // 默认隐藏弹出框
        dialogFormVisible: false,
        // npc打样任务数据对象
        npcTaskData:{

        },
        checkForm:{
          dg_checkStatus:1,
        }
      };
    },
    mounted() {
       this.getNpcTask();
    },
    methods: {
      // 获取打样信息
      getNpcTask() {
       this.axios.post(this.lib.config.host.vendorDlv + "/vendormgt/npc/npcTask/getNpcTask/" + this.$route.query.npcTaskId)
          .then((response)=>{
            this.npcTaskData = response.data;
            this.publishStatus = response.data.publishStatus;
            this.checkStatus = response.data.checkStatus;
          })
          .catch((error)=>{
            console.log(error);
          });
      },
      // 审核打样任务
      check() {
        //修改弹框
        this.dialogFormVisible = true
      },
      // 发布打样任务
      publish(){
        this.$confirm('确定执行此操作?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
           this.axios.put(this.lib.config.host.vendorDlv + "/vendormgt/npc/npcTask/publish/" + this.$route.query.npcTaskId).then((response)=>{
              this.$message({
                type: 'success',
                message: '发布成功!'
              });
              this.getNpcTask();
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '取消发布'
          });
        });
      },
      // 提交审核
      submitCheck(checkForm) {
        this.dialogFormVisible=false;
        this.axios.post(this.lib.config.host.vendorDlv + "/vendormgt/npc/npcTask/check/" +  this.$route.query.npcTaskId, qs.stringify(checkForm))
        .then((response)=>{
          this.getNpcTask();
        })
        .catch((error)=>{
          console.log(error);
        });
      },
      // 下载附件
      downloadFiles(filePath,fileName){
        this.downloadFile(filePath, fileName);
      }
    }
  }
</script>
